import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
	list = '/user/bsUserlayoutAgentinfors/list',
	save = '/user/bsUserlayoutAgentinfors/add',
	edit = '/user/bsUserlayoutAgentinfors/edit',
	deleteOne = '/user/bsUserlayoutAgentinfors/delete',
	deleteBatch = '/user/bsUserlayoutAgentinfors/deleteBatch',
	importExcel = '/user/bsUserlayoutAgentinfors/importExcel',
	exportXls = '/user/bsUserlayoutAgentinfors/exportXls',
	bsUserlayoutAgentReportList = '/user/bsUserlayoutAgentinfors/listBsUserlayoutAgentReportByMainId',
	bsUserlayoutAgentReportSave = '/user/bsUserlayoutAgentinfors/addBsUserlayoutAgentReport',
	bsUserlayoutAgentReportEdit = '/user/bsUserlayoutAgentinfors/editBsUserlayoutAgentReport',
	bsUserlayoutAgentReportDelete = '/user/bsUserlayoutAgentinfors/deleteBsUserlayoutAgentReport',
	bsUserlayoutAgentReportDeleteBatch = '/user/bsUserlayoutAgentinfors/deleteBatchBsUserlayoutAgentReport',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
	defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
	return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
		handleSuccess();
	});
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
	createConfirm({
		iconType: 'warning',
		title: '确认删除',
		content: '是否删除选中数据',
		okText: '确认',
		cancelText: '取消',
		onOk: () => {
			return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
				handleSuccess();
			});
		}
	});
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
	let extInfors = {}
	extInfors.remark = params.remark
	params.extInfors = JSON.stringify(extInfors)
	let url = isUpdate ? Api.edit : Api.save;
	return defHttp.post({ url: url, params });
}

/**
 * 列表接口
 * @param params
 */
export const bsUserlayoutAgentReportList = (params) => {
	if (params['agentid']) {
		return defHttp.get({ url: Api.bsUserlayoutAgentReportList, params });
	}
	return Promise.resolve({});
}


/**
 * 删除单个
 */
export const bsUserlayoutAgentReportDelete = (params, handleSuccess) => {
	return defHttp.delete({ url: Api.bsUserlayoutAgentReportDelete, params }, { joinParamsToUrl: true }).then(() => {
		handleSuccess();
	});
}
/**
 * 批量删除
 * @param params
 */
export const bsUserlayoutAgentReportDeleteBatch = (params, handleSuccess) => {
	createConfirm({
		iconType: 'warning',
		title: '确认删除',
		content: '是否删除选中数据',
		okText: '确认',
		cancelText: '取消',
		onOk: () => {
			return defHttp.delete({ url: Api.bsUserlayoutAgentReportDeleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
				handleSuccess();
			});
		}
	});
}
/**
 * 保存或者更新
 * @param params
 */
export const bsUserlayoutAgentReportSaveOrUpdate = (params, isUpdate) => {
	let url = isUpdate ? Api.bsUserlayoutAgentReportEdit : Api.bsUserlayoutAgentReportSave;
	return defHttp.post({ url: url, params });
}
/**
 * 导入
 */
export const bsUserlayoutAgentReportImportUrl = '/user/bsUserlayoutAgentinfors/importBsUserlayoutAgentReport'

/**
 * 导出
 */
export const bsUserlayoutAgentReportExportXlsUrl = '/user/bsUserlayoutAgentinfors/exportBsUserlayoutAgentReport'